package zhizhemodi.tech.short_term_bwork.service;

import java.util.LinkedList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import zhizhemodi.tech.short_term_bwork.entity.ProgramFileList;
import zhizhemodi.tech.short_term_bwork.mapper.ProgramFileListMapper;

@Repository
public class ProgramFileListService {
    
    @Autowired
    ProgramFileListMapper programFileListMapper;

    @Resource
    DirFileService dirFileService;

    public List<ProgramFileList> getProgramFileListByProgramId(Integer programId) {
        QueryWrapper<ProgramFileList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("program_id", programId);
        return programFileListMapper.selectList(queryWrapper);
    }

    public List<String> getFileListByProgramId(Integer programId) {
        List<String> re = new LinkedList<>();
        List<ProgramFileList> files = getProgramFileListByProgramId(programId);
        for(ProgramFileList file : files) {
            re.add("http://zhizhemodi.tech:10110/file/download?url=" + dirFileService.getFile(null, file.getFileId()).getFileName());
        }
        return re;
    }

    /**
     * 根据节目Id删除
     * @param programId
     */
    public void deleteByProgramId(Integer programId) {
        QueryWrapper<ProgramFileList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("program_id", programId);
        programFileListMapper.delete(queryWrapper);
    }

}
